
#include "ping.h"

void send_v4() {

    int len;
    struct icmp * icmp;

    icmp = (struct icmp *)Instance()->buffer;
    icmp->icmp_type = ICMP_ECHO;
    icmp->icmp_code = 0;
    icmp->icmp_id   = Instance()->pid;
    icmp->icmp_seq  = Instance()->nsend++;

    memset(icmp->icmp_data, 0xa5, Instance()->datalen);

    gettimeofday((struct timeval *)icmp->icmp_data, NULL);

    len = 8 + Instance()->datalen;
    icmp->icmp_cksum = 0;
    icmp->icmp_cksum = in_sksum((u_short *)icmp, len);

    ssize_t result = sendto(Instance()->sockfd, Instance()->buffer, len, 0, Instance()->pr->sasend, Instance()->pr->salen);

    // printf("sendto result %ld\n", result);
}